﻿package mortal.game.view.heroArena.view
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.common.*;
    import mortal.game.view.heroArena.util.*;

    public class HeroArenaTeamInfoCell extends GSprite
    {
        private var _teamImg:GBitmap;
        private var _roleName:GTextFiled;
        private var _combat:GTextFiled;
        private var _careerLevel:GTextFiled;
        private var _invateBtn:GButton;
        private var _leaveBtn:GButton;
        private var _breakBtn:GButton;
        private var _shotOffBtn:GButton;
        private var _data:SArenaBasePlayer;

        public function HeroArenaTeamInfoCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(0, 0, 280, 42, this, ImagesConst.RankingListBg));
            this._teamImg = UIFactory.gBitmap(ImagesConst.CaptainIcon, 3, 9, this);
            this._teamImg.width = 22;
            this._teamImg.height = 22;
            this._teamImg.visible = false;
            this._roleName = UIFactory.gTextField("", 27, 8 - 5, 100, 20, this);
            this._combat = UIFactory.gTextField("", 27, 26 - 5, 105, 20, this, GlobalStyle.textFormatHuang2);
            this._careerLevel = UIFactory.gTextField("", 134, 15 - 5, 89, 20, this);
            this._invateBtn = UIFactory.gButton(Language.getString(41633), 225, 13 - 5, 44, 19, this);
            this._leaveBtn = UIFactory.gButton(Language.getString(41634), 225, 13 - 5, 44, 19, this);
            this._breakBtn = UIFactory.gButton(Language.getString(41635), 225, 13 - 5, 44, 19, this);
            this._shotOffBtn = UIFactory.gButton(Language.getString(41636), 225, 13 - 5, 44, 19, this);
            this._leaveBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._invateBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._breakBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._shotOffBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._leaveBtn.visible = false;
            this._invateBtn.visible = false;
            this._breakBtn.visible = false;
            this._shotOffBtn.visible = false;
            return;
        }// end function

        public function set data(param1:SArenaBasePlayer) : void
        {
            var _loc_3:String = null;
            this._data = param1;
            this.clear();
            if (this._data.entityId.id != 0)
            {
                this._teamImg.visible = this._data.isCap;
                this._roleName.text = this._data.name;
                this._combat.text = Language.getString(41637) + this._data.combat;
                _loc_3 = GameDefConfig.instance.getCarrer(this._data.career);
                this._careerLevel.htmlText = this._data.level + Language.getString(41638) + HTMLUtil.addColor(_loc_3, GlobalStyle.colorHuang2);
            }
            var _loc_2:* = Cache.instance.role.entityInfo.entityId;
            if (HeroArenaUtil.isSelfTeamLeader())
            {
                if (this._data.entityId.id != 0 && this._data.isCap)
                {
                    this._breakBtn.visible = true;
                }
                else if (this._data.entityId.id != 0 && !this._data.isCap)
                {
                    this._shotOffBtn.visible = true;
                }
                else if (this._data.entityId.id == 0)
                {
                    this._invateBtn.visible = true;
                }
            }
            else if (!this._data.isCap)
            {
                this._leaveBtn.visible = true;
            }
            return;
        }// end function

        private function clear() : void
        {
            this._teamImg.visible = false;
            this._roleName.text = "";
            this._combat.text = "";
            this._careerLevel.text = "";
            this._invateBtn.visible = false;
            this._leaveBtn.visible = false;
            this._breakBtn.visible = false;
            this._shotOffBtn.visible = false;
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            if (!GameMapUtil.curMapState.isHeroArenaRestRoomMap)
            {
                MsgManager.showRollTipsMsg(Language.getString(41639));
                return;
            }
            if (GameController.copy.heroArenaCopy.isMatchSucc)
            {
                MsgManager.showRollTipsMsg(Language.getString(41640));
                return;
            }
            if (event.target == this._invateBtn)
            {
                HeroArenaTeamInvateWin.instance.show();
            }
            var _loc_2:* = Language.getString(41641);
            if (event.target == this._leaveBtn)
            {
                GameProxy.copy.quitArenaTeam();
            }
            if (event.target == this._breakBtn)
            {
                GameProxy.copy.disbandArenaTeam();
            }
            if (event.target == this._shotOffBtn)
            {
                GameProxy.copy.kickoutArenaTeam();
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._teamImg.dispose();
            this._teamImg = null;
            this._roleName.dispose();
            this._roleName = null;
            this._combat.dispose();
            this._combat = null;
            this._careerLevel.dispose();
            this._careerLevel = null;
            this._invateBtn.dispose();
            this._invateBtn = null;
            this._leaveBtn.dispose();
            this._leaveBtn = null;
            this._breakBtn.dispose();
            this._breakBtn = null;
            this._shotOffBtn.dispose();
            this._shotOffBtn = null;
            this._data = null;
            return;
        }// end function

    }
}
